The Euclidean Algorithm

Introduction

What Is the Greatest Common Divisor?

Why Finding the GCD Matters

A First Look at the Euclidean Algorithm

The Key Idea: Replacing Big Problems with Smaller Ones

Step‑by‑Step Examples

Example 1: $\gcd(252, 105)$

  1. $252 = 105\cdot 2 + 42$
  2. $105 = 42\cdot 2 + 21$
  3. $42 = 21\cdot 2 + 0$

Example 2: $\gcd(119, 34)$

  1. $119 = 34\cdot 3 + 17$
  2. $34 = 17\cdot 2 + 0$

Example 3: $\gcd(48, 18)$

  1. $48 = 18\cdot 2 + 12$
  2. $18 = 12\cdot 1 + 6$
  3. $12 = 6\cdot 2 + 0$

Why the Euclidean Algorithm Always Works

Extending the Algorithm to Negative Integers

Common Mistakes and How to Avoid Them

Calculator

GCD

  • Returns the greatest common divisor of two numbers.
gcd(252, 105) gcd(48, 18)

GCD Verbose

  • Calculates the greatest common divisor of two numbers.
  • Shows the intermediate steps.
gcdVerbose(252, 105) gcdVerbose(48, 18)

Exercises

Try to compute each GCD using the Euclidean Algorithm.
Show the sequence of divisions when possible.

  1. Compute $\gcd(84, 30)$.

    Solution

    $\gcd(84, 30)$

    • $84 = 30\cdot 2 + 24$
    • $30 = 24\cdot 1 + 6$
    • $24 = 6\cdot 4 + 0$
    • Last nonzero remainder: $6$
    • Answer: $\gcd(84, 30) = 6$.
  2. Compute $\gcd(99, 78)$.

    Solution

    $\gcd(99, 78)$

    • $99 = 78\cdot 1 + 21$
    • $78 = 21\cdot 3 + 15$
    • $21 = 15\cdot 1 + 6$
    • $15 = 6\cdot 2 + 3$
    • $6 = 3\cdot 2 + 0$
    • Last nonzero remainder: $3$
    • Answer: $\gcd(99, 78) = 3$.
  3. Compute $\gcd(56, 15)$.

    Solution

    $\gcd(56, 15)$

    • $56 = 15\cdot 3 + 11$
    • $15 = 11\cdot 1 + 4$
    • $11 = 4\cdot 2 + 3$
    • $4 = 3\cdot 1 + 1$
    • $3 = 1\cdot 3 + 0$
    • Last nonzero remainder: $1$
    • Answer: $\gcd(56, 15) = 1$.
  4. Compute $\gcd(144, 60)$.

    Solution

    $\gcd(144, 60)$

    • $144 = 60\cdot 2 + 24$
    • $60 = 24\cdot 2 + 12$
    • $24 = 12\cdot 2 + 0$
    • Last nonzero remainder: $12$
    • Answer: $\gcd(144, 60) = 12$.
  5. Compute $\gcd(101, 23)$.

    Solution

    $\gcd(101, 23)$

    • $101 = 23\cdot 4 + 9$
    • $23 = 9\cdot 2 + 5$
    • $9 = 5\cdot 1 + 4$
    • $5 = 4\cdot 1 + 1$
    • $4 = 1\cdot 4 + 0$
    • Last nonzero remainder: $1$
    • Answer: $\gcd(101, 23) = 1$.
  6. Compute $\gcd(270, 192)$.

    Solution

    $\gcd(270, 192)$

    • $270 = 192\cdot 1 + 78$
    • $192 = 78\cdot 2 + 36$
    • $78 = 36\cdot 2 + 6$
    • $36 = 6\cdot 6 + 0$
    • Last nonzero remainder: $6$
    • Answer: $\gcd(270, 192) = 6$.
  7. Compute $\gcd(1{,}001, 143)$.

    Solution

    $\gcd(1{,}001, 143)$

    • $1{,}001 = 143\cdot 7 + 0$
    • Last nonzero remainder: $143$
    • Answer: $\gcd(1{,}001, 143) = 143$.
  8. Compute $\gcd(48, 7)$.

    Solution

    $\gcd(48, 7)$

    • $48 = 7\cdot 6 + 6$
    • $7 = 6\cdot 1 + 1$
    • $6 = 1\cdot 6 + 0$
    • Last nonzero remainder: $1$
    • Answer: $\gcd(48, 7) = 1$.
  9. Compute $\gcd(-72, 30)$ (remember to use absolute values).

    Solution

    $\gcd(-72, 30)$

    • First use absolute values: $\gcd(-72, 30) = \gcd(72, 30)$.
    • $72 = 30\cdot 2 + 12$
    • $30 = 12\cdot 2 + 6$
    • $12 = 6\cdot 2 + 0$
    • Last nonzero remainder: $6$
    • Answer: $\gcd(-72, 30) = 6$.
  10. True or false: If $a$ divides $b$, then $\gcd(a, b) = a$.

    Solution

    True or false: If $a$ divides $b$, then $\gcd(a, b) = a$

    • If $a$ divides $b$, then $b = ak$ for some integer $k$.
    • Any common divisor of $a$ and $b$ must divide $a$ (because $a$ already divides $b$).
    • So the largest common divisor is $a$ itself.
    • Answer: True.